package com.hlkj.warboot.module_sys.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hlkj.warboot.configurer.util.ResponseUtil;
import com.hlkj.warboot.module_sys.entity.AdminEntity;
import com.hlkj.warboot.module_sys.mapper.AdminMapper;
import com.hlkj.warboot.module_sys.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: lixing
 * @Date: 2020/12/9 20:02
 */
@RequestMapping("demo")
@RestController
@Slf4j
public class DemoController {

    @Resource
    private AdminService adminService;

    @Resource
    private AdminMapper adminMapper;

    @RequestMapping("page")
    public Object page(AdminEntity adminEntity) {
        Page<AdminEntity> adminEntityList = adminMapper.adminPage(new Page<>(1,100), adminEntity);
        return adminEntityList;
    }

    private int sum = 0;
    @GetMapping("demo")
    public void demo() {
        sum += 1;
        log.error("sum的值：" + sum);
    }

    // http://127.0.0.1:8752/warboot/demo/redis/0
    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @Transactional
    @RequestMapping("redis/{flag}")
    public Object redis(@PathVariable("flag") Integer flag) {
        AdminEntity adminEntity = adminService.getById(888888888888888888L);
        adminEntity.setSex(0);
        boolean result = adminService.updateById(adminEntity);
        //
        redisTemplate.opsForValue().set("name", "name");
        //
        if (0==flag) {
            System.out.println(0/0);
        }
        return ResponseUtil.success();
    }
}
